package com.xx.springboot.DataStructure.LeetCode.LinkedList;

/**
 * Created by xiaoxiunique on 2018-7-26.
 */
public class ListNode {
    int val;
    ListNode next;
    ListNode(int x) {
        val = x;
    }

    ListNode(int[] arr){
        if (arr == null || arr.length == 0)
            throw new IllegalArgumentException("array is null");

        this.val = arr[0];
        ListNode cur = this;
        for (int i = 1; i < arr.length; i++) {
            cur.next = new ListNode(arr[i]);
            cur = cur.next;
        }
    }

    @Override
    public String toString() {
        StringBuffer res = new StringBuffer();

        ListNode cur = this;
        while (cur != null) {
            res.append(cur.val + "->");
            cur = cur.next;
        }
        res.append("NULL");
        return  res.toString();
    }

}
